package fuse.LaCollaFS.Metadades;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.rmi.RemoteException;

import LaColla.Api.Api;
import LaColla.core.data.TimestampSummary;
import LaColla.core.util.Debug;
import fuse.LaCollaFS.Api.ApiImpl;
import fuse.LaCollaFS.Api.ApiServer;
import junit.framework.TestCase;

public class testMetaDades extends TestCase{
	private static MetaDades dades;
	
	private String defpath = "/tmp/lacollafs";

	private static final int RMIport = 11099;

	private static String appIP;

	private static int apiPort = 19000;

	private static int appPort = 4321;

	private static String username = "admin";

	private static String passwd = "admin";

	private static String groupId = "hola";

	private Api api;

	private ApiServer aserv;

	private String memberId;

	private String apiid;

	public void constructor() {

		try {
			appIP = InetAddress.getLocalHost().getCanonicalHostName();
		} catch (UnknownHostException e1) {

			e1.printStackTrace();
		}
		Debug.say("hola LaCollaFS", appIP);
		p("Host= " + appIP + " appPort=" + appPort + " LaCOLLAport= " + apiPort);

		aserv = new ApiServer(appIP, appPort);
		p("Api Server creat..." + aserv);

		api = aserv.resolveApi(apiPort);
		TimestampSummary s;
		s = aserv.readSummary();
		// p("tss:"+s);

		String gapaIP = appIP;
		int gapaPort = 2001;
		try {
			apiid = api.login(groupId, username, passwd, gapaIP, gapaPort,
					appIP, appPort, aserv.readSummary());
		} catch (RemoteException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		// en aquest punt encara pot no haber arribat el
		// newConnectedMemberEvent, s'hauria de bloquejar..
		try {
			Thread.sleep(1000);
		} catch (Exception e) {
		} // esperem rebre l'event
		memberId = ((ApiImpl) aserv.getASAI()).getMemberId();
		//p("Membre conectat, el meu id és : " + memberId);
	}
	private void p(Object o) {
		System.out.println(o);
		// TODO Auto-generated method stub
		
	}
	public void testMetaDades() throws RemoteException{
		

		
			constructor();
			MetaDades dades = new MetaDades(defpath, api, aserv, apiid);
			dades.ObtenirDir("/hola");
			
		
		
	}
}
